<template>
  <div class="register">
        <alertTip v-if="showAlert" @closeTip="go()" :alertText="alertText"></alertTip>

    <!--<headers :title="title"></headers>-->
    <!--<headers title="注册"></headers>-->
    <div class="register_content">
      <p style="text-align: center" class="p1">
        <img src="../assets/images/login/logo.png" alt="" >
        <!--<b>{{this.title}}</b>-->
        <b>注册</b>
      </p>
      <input type="tel" placeholder="请输入您的手机号" v-model="telephone">
      <hr>
      <button style="display: block;" @click="getCode()"><img src="../assets/images/login/btn.png" alt=""></button>

      <!--<p v-if="this.show" class="p2">注册即视为同意xxx的用户协议</p>-->
      <!--<p v-else="show" class="p2">1111111111111</p>-->
      <!--<p class="p2">{{this.xieyi}}</p>-->
      <p class="p2">注册即为同意xxx的用户协议</p>
    </div>

  </div>
</template>


<script>
  import wx from 'weixin-js-sdk'
  import { wxHttpTool,wx_config, http_getParam, get_shopQrcoe,wx_share,wx_hideAllMenu } from '../components/httpUtil/httpUtil'
  import {msg_10046} from '../message/msg_10046'
  /* eslint-disable semi,space-before-blocks,space-before-function-paren */
import {relogin} from "../components/httpUtil/httpUtil";

  let reg = /^1[34578]\d{9}$/;
  let data = {
    telephone: ''
//    show: ''
//    title:'xx',
  }
  export default {
    name: 'register',
    data () {
      return{
        data,
        showAlert:false,
        alertText:null
      }
    },
    methods: {
      alertTip(msg){
        this.showAlert = true;
        this.alertText = msg;
      },
      go(){
        this.showAlert = false
        },
      getCode () {
        if (!reg.test(this.telephone)) {
          this.alertTip("手机格式不正确");
          this.go = function(){
             this.showAlert = false;
          }
          // alert('手机格式不正确')
          this.telephone = ''
        } else {
          localStorage.setItem('phone', JSON.stringify(this.telephone)); // 全局可以直接拿到，不用传递了
//          this.$router.push({name: 'codeCheck', params: {phone: localStorage.phone}});
          this.$router.push('/codeCheck');
          const jsonValue = JSON.stringify({
            'c': '10003',
            'p': {
              'mobile': this.telephone  // 帐号
            }
          });
          this.$http.post(api + '/qqs.us', jsonValue).then((res) => {
            console.log(res.data);
            //          this.$emit('has-log', res.data.username);
          }, (res) => {
            this.alertTip("网络错误");
            this.go = function(){
               this.showAlert = false;
            }
            // alert('网络错误');
          })
        }
      }
    },
    created () {
      wxHttpTool.wxAuthor(this, function (varRet, varJson, varThis = this) {
        if (varRet == -1) {
          varThis.alertTip('网络错误');
          varThis.go = function () {
            varThis.showAlert = false;
          }

        }
        // 关注钱应该判断下是否已经关注过了
        msg_10046.send(varThis,msg_10046.entity(),function(varThis,res){
          varThis.wxlist=res.data.p.sign
          wx_config(varThis.wxlist);
          wx_hideAllMenu();
          wx.hideMenuItems({
            //禁用单独分享朋友圈QQ空间等功能
            menuList: ["menuItem:share:timeline","menuItem:share:QZone","menuItem:share:qq"] // 要隐藏的菜单项，所有menu项见附录3
          });
        })


      },this.type)
      // 获取到登录页面的参数
      this.telephone = this.$route.params.tel;
// //      this.show = this.$route.params.show;
//      this.xieyi = this.$route.params.xieyi;
// //      console.log(this.title, this.show)
// //      change();
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  .register{
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    /*padding: 80px 0 0;*/
    box-sizing: border-box;
  }
  .register_content{
    display: flex;
    flex-direction: column;
    align-items: center;
    /*font-size: 16px;*/
    margin-top:20%;
  }
  .register_content input{
    border: none;
    outline: none;
    font-size: 30px;
    text-align: center;
    margin-top: 50px;
    /*margin-left: 6rem;*/
  }
  .register_content .p1 b{
    display: block;
    font-size: 30px;
    margin-top: 30px;
  }
  .register_content .p1 img{
    width: 145px;
    height: 145px;
  }
  .register_content .p2{
    font-size: 20px;
    color: #ccc;
  }
  .register_content hr{
    width: 515px;
    margin: 20px 0 30px;
  }
  .register_content button{
    border: none;
    outline: none;
    /*background: #FD5F3F;*/
    border-radius: 50px;
    width: 470px;
    height: 75px;
    /*font-size: 1.2rem;*/
    /*color: #fff;*/
    margin: 40px 0 40px;
  }
  .register_content button img{
    width: 470px;
    height: 70px;
  }
</style>
